<%@ LANGUAGE="VBSCRIPT" %>
<% option explicit%>
<% Response.Expires=0 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
dim Node, Tel, Res
Node=request("Node")
if isEmpty(Node) then Node="_P"
Res=request("Res")
if isEmpty(Res) then Res="OK"
Tel=request("Tel")

%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">

</head>

<body bgcolor="#FBF3BB"  >
<%
	Dim cnn
	Dim  color,  TT,T1,T2,T3, SS1p, SS4p, SS11p,SS1m, SS4m, SS11m,SS1, SS4, SS11
	Dim connStr
	Dim objRec
	Set cnn=Server.CreateObject("ADODB.Connection")
	Set objRec=Server.CreateObject("ADODB.Recordset")
	connStr="Provider=SQLOLEDB.1;Persist Security Info=True;User ID=Test;Password=Test;Initial Catalog=SMS"&Node&";Data Source=(local)"
	cnn.open connStr

	if Res="OK"  THEN
		T1=" WHERE "
		T2=" ServiceResultCode=0 "
		T3=" AND "
	ELSE
		T1=""
		T2=""
		T3=""
	END IF
	SS1=0
	SS11=0.0
	SS4=0.0
	SS1p=0
	SS11p=0.0
	SS4p=0.0
	SS1m=0
	SS11m=0.0
	SS4m=0.0

	if Tel="" THEN
		objRec.open "select * from SMS_P.dbo.[View_Payments] "&T1&T2, cnn,1,3,1
	ELSE
		objRec.open "select * from SMS_P.dbo.[View_Payments] where (MainPhone='"&Tel&"'" & T3 &T2 & ") OR (CmdCode='PM' AND (TagPhone='"&Tel&"'" & T3 &T2& "))", cnn,1,3,1

IF NOT 	objRec.eof THEN%>
<table width=90% border="0"><tr><td align=center width=80%><h3 align=center>Payments for account <%=Request("tel")%> </h3></td> <td ALIGN=RIGHT><a href="vp.asp?node=_P&tel=&Res=<%=request("Res")%>">All accounts</a> </td></tr>
</table>
	<%
ELSE%>
No records
<%
response.end
END IF
	END IF
	%>

	<table border="1" width="98%" align="center" cellpadding=4>
	<tr align="center">
<th  align="center">Date</th>
<th><font size=-1>FromPhone</font></th>
<%	if Tel="" THEN%>
<th><font size=-1>MainPhone</font></th>
<%END IF%>
<th><font size=-1>SubAccount</font></th>
<th><font size=-1>Operation</font></th>
<th><font size=-1>TagPhone</font></th>
<th><font size=-1>Summa</font></th>
<th><font size=-1><%=Res%> Result (&nbsp; ===>
<%IF Res="ALL" THEN%>
<a href="vp.asp?node=_P&tel=<%=Tel%>&Res=OK">OK</a>
<%END IF%>
<%IF Res="OK" THEN%>
<a href="vp.asp?node=_P&tel=<%=Tel%>&Res=ALL">ALL</a>
<%END IF%>
)</font></th>
<th><font size=-1>SentTime</font></th>
</tr>
	<%
	Do while (Not objRec.eof) 
TT=objRec("PhoneSub")
IF objRec("PhoneSub")="4" THEN TT="self"
IF objRec("PhoneSub")="11" THEN TT="i-dealer"
IF objRec("PhoneSub")="1" THEN TT="demo"
IF objRec("PhoneSub")="7" THEN TT="keno"
IF objRec("PhoneSub")="8" THEN TT="win"
DIM CA, CT, ST,S, S4, S11, S1
IF objRec("Address")=objRec("MainPhone") THEN
	CA="black"
ELSE
	CA="brown"
END IF
IF objRec("TagPhone")=objRec("MainPhone") THEN
	CT="black"
ELSE
	CT="green"
END IF

IF IsNULL(objRec("Sum")) OR IsEmpty(objRec("Sum")) THEN
	sT=""
	S=0.0
ELSE
	IF objRec("CMDCode")="AM" THEN
		St=objRec("Sum")
		S=CDbl(St)
	ELSEIF objRec("CMDCode")="PM" and objRec("TagPhone")=request("Tel")  THEN
		St=objRec("Sum")
		S=CDbl(St)
		St="<font color=navy>"&St&"</font>"
	ELSE
		St=objRec("Sum")
		S=-CDbl(St)
		St="-"&St
	END IF	
	IF IsNULL(objRec("ServiceResultCode")) OR objRec("ServiceResultCode")<>0 THEN
		St="<font color=brown><"&St&"></font>"
		S=0.0
	END IF	
END IF

IF NOT IsEmpty(Tel) AND NOT IsNULL(Tel) AND Tel<>"" THEN
	SELECT CASE objRec("PhoneSub")
	CASE 1
		St="<font color=purple>"&St&"</font>"
		IF S >= 0 THEN SS1p=SS1p+S ELSE SS1m=SS1m+S
		SS1=SS1+S
	CASE 4
		IF S >= 0 THEN SS4p=SS4p+S ELSE SS4m=SS4m+S
		SS4=SS4+S
	CASE 11
		IF S >= 0 THEN SS11p=SS11p+S ELSE SS11m=SS11m+S
		SS11=SS11+S
	CASE ELSE
		St="<font color=c0c0c0>{"&St&"}</font>"
	
	END SELECT
END IF

    %>
	<tr align="center">
<td><font size=-2><%=objRec("GetTime")   %></font></td>
<td  title="SMS# <%=objRec("SMS_id")%> : <%=objRec("SMS_Message")%>"><font size=-2 color="<%=CA%>"><%=objRec("Address")%></font></td>
<%	if Tel="" THEN%>
<td title="Acc: <%=objRec("Account")%>"><font size=-2><a href="vp.asp?node=_P&tel=<%= objRec("MainPhone")%>&Res=<%=request("Res")%>"><%= objRec("MainPhone")  %></font></td>
<%END IF%>
<td><font size=-2><%=TT%></font></td>
<td><font size=-2><%=objRec("CMDCode")%></font></td>
<td><font size=-2 color="<%=CT%>"><%= objRec("TagPhone")%>
<%IF (objRec("PhoneSub")<>objRec("TagPhoneSub")) AND objRec("CMDCode")<>"MEA" AND objRec("CMDCode")<>"MTC" AND objRec("CMDCode")<>"SKY"  THEN%>
#<%=objRec("TagPhoneSub")%>
<%END IF%>
&nbsp;</font></td>
<td><font size=-1><%=St%>&nbsp;</font></td>
<%
IF objRec("ServiceResultCode")=0 THEN
Color="Black"
ELSE
Color="Brown"
END IF
%>
<td><font size=-2 color="<%=Color%>"><%=objRec("ServiceResultText")%>&nbsp;</font></td>
<td><font size=-2><%=objRec("SentTime")%>&nbsp;</font></font></td></tr>
<%	objRec.MoveNext
	Loop 
	%>
	</table>

<%IF NOT IsEmpty(Tel) AND NOT IsNULL(Tel) AND Tel<>"" THEN%>
<h3 align=center>Summary  for account <%=tel%> </h3>
<table border=1 cellpadding=6 align=center>
	<tr align="center">
<td  align="center">Self</td>
<td  align="center">Rub</td>
<td  align="center">Received</td>
<td  align="center"><strong><%=SS4p%></strong></td>
<td  align="center">Paid</td>
<td  align="center"><strong><%=SS4m%></strong></td>
<td  align="center">Summary</td>
<td  align="center"><strong><%=SS4%></strong></td>
</tr>
	<tr align="center">
<td  align="center">i-dealer</td>
<td  align="center">Rub</td>
<td  align="center">Received</td>
<td  align="center"><strong><%=SS11p%></strong></td>
<td  align="center">Paid</td>
<td  align="center"><strong><%=SS11m%></strong></td>
<td  align="center">Summary</td>
<td  align="center"><strong><%=SS11%></strong></td>
</tr>
	<tr align="center">
<td  align="center">Demo</td>
<td  align="center">DemoRub</td>
<td  align="center">Received</td>
<td  align="center"><strong><%=SS1p%></strong></td>
<td  align="center">Paid</td>
<td  align="center"><strong><%=SS1m%></strong></td>
<td  align="center">Summary</td>
<td  align="center"><strong><%=SS1%></strong></td>
</tr>

	</table>
		<%
END IF
	cnn.Close
	set cnn=nothing
	set objRec=nothing
%>
</font>
</body>
</html>
